package net.slidinglive.utilities.adapter;

import net.slidinglive.utilities.enumeration.ContactSource;
import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

/**
 * @author Sebastian Hoffmann <bo.hoffi@gmail.com>
 */
public class ContactSourceAdapter
        implements SpinnerAdapter {

    private final Context context;

    public ContactSourceAdapter(final Context context) {

        this.context = context;
    }

    @Override
    public int getCount() {

        return ContactSource.values().length;
    }

    @Override
    public Object getItem(int position) {

        return ContactSource.values()[position];
    }

    @Override
    public long getItemId(int position) {

        return 0;
    }

    @Override
    public int getItemViewType(int position) {

        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ContactSource ms = (ContactSource) this.getItem(position);
        final TextView t = new TextView(this.context);

        t.setTag(ms);
        t.setText(ms.getCaption(this.context));

        return t;
    }

    @Override
    public int getViewTypeCount() {

        return 0;
    }

    @Override
    public boolean hasStableIds() {

        return false;
    }

    @Override
    public boolean isEmpty() {

        return this.getCount() == 0;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver observer) {

        // TODO Auto-generated method stub

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {

        // TODO Auto-generated method stub

    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {

        final ContactSource ms = (ContactSource) this.getItem(position);
        final TextView t = new TextView(this.context);

        t.setTag(ms);
        t.setText(ms.getCaption(this.context));

        return t;
    }
}